define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'promotion/goods/index' + location.search,
                    add_url: 'promotion/goods/add',
                    edit_url: 'promotion/goods/edit',
                    del_url: 'promotion/goods/del',
                    multi_url: 'promotion/goods/multi',
                    import_url: 'promotion/goods/import',
                    table: 'promotion_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                Search:true,
                commonSearch:true,
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'good.image', title: __('Goods.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'type', title: __('Type'), operate: false, searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'good.title', title: __('Goods.title'), operate: 'LIKE'},
                        {field: 'good.price', title: __('售价（元）'), operate:false},
                        {field: 'c1', title: __('推广员商品比例'), operate:false},
                        {field: 'scale', title: __('Scale'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        // {field: 'goods_id', title: __('Goods_id')},
                        
                       
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'goods.id', title: __('Goods.id')},
                        // {field: 'goods.shop_id', title: __('Goods.shop_id')},
                        // {field: 'goods.shop_category_id', title: __('Goods.shop_category_id'), operate: 'LIKE'},
                        // {field: 'goods.category_id', title: __('Goods.category_id')},
                        // {field: 'goods.brand_id', title: __('Goods.brand_id')},
                        // {field: 'goods.category_attribute', title: __('Goods.category_attribute')},
                       
                      
                        // {field: 'goods.images', title: __('Goods.images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'goods.description', title: __('Goods.description'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'goods.flag', title: __('Goods.flag'), operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'goods.stock', title: __('Goods.stock')},
                        // {field: 'goods.content', title: __('Goods.content')},
                        // {field: 'goods.freight_id', title: __('Goods.freight_id')},
                        // {field: 'goods.grounding', title: __('Goods.grounding')},
                        // {field: 'goods.specs', title: __('Goods.specs')},
                        // {field: 'goods.distribution', title: __('Goods.distribution')},
                        // {field: 'goods.activity', title: __('Goods.activity')},
                        // {field: 'goods.activity_id', title: __('Goods.activity_id')},
                        // {field: 'goods.activity_type', title: __('Goods.activity_type')},
                        // {field: 'goods.views', title: __('Goods.views')},
                       
                        // {field: 'goods.sales', title: __('Goods.sales')},
                        // {field: 'goods.payment', title: __('Goods.payment')},
                        // {field: 'goods.comment', title: __('Goods.comment')},
                        // {field: 'goods.praise', title: __('Goods.praise')},
                        // {field: 'goods.moderate', title: __('Goods.moderate')},
                        // {field: 'goods.negative', title: __('Goods.negative')},
                        // {field: 'goods.like', title: __('Goods.like')},
                        // {field: 'goods.weigh', title: __('Goods.weigh')},
                        // {field: 'goods.createtime', title: __('Goods.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'goods.updatetime', title: __('Goods.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'goods.deletetime', title: __('Goods.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'goods.status', title: __('Goods.status'), formatter: Table.api.formatter.status},
                        // {field: 'goods.code', title: __('Goods.code'), operate: 'LIKE'},
                        // {field: 'goods.unit', title: __('Goods.unit'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'goods.tags', title: __('Goods.tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        // {field: 'goods.channel', title: __('Goods.channel'), operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'goods.video', title: __('Goods.video'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'goods.gdtype', title: __('Goods.gdtype')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'promotion/goods/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'promotion/goods/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'promotion/goods/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
